<template>
  <div>
    <div class="bg-white grid-content">
      <div style="overflow: hidden; padding-bottom:8px;">
        <!-- <div class="mytitle"><svg-icon icon-class="yjbb" class="myIcon" />油水井措施情况</div>
        <div class="myButtons">
          <el-button @click="handleClick('', 'add')">新增</el-button>
        </div> -->
      </div>
      <!-- 表格 -->
      <el-table :data="tableData" :header-cell-style="{background:'#F5F7FA',color:'#909399'}" border stripe> 
        <el-table-column align="center" type="index" label="序号" :index="indexMethod" width="60">
          </el-table-column>
          <el-table-column align="center" prop="csid" label="措施ID">
          </el-table-column>
          <el-table-column align="center" prop="jh" label="井号">
          </el-table-column>
          <el-table-column align="center" prop="rq" label="日期">
          </el-table-column>
          <el-table-column align="center" prop="cslx" label="措施类型">
          </el-table-column>
          <el-table-column align="center" prop="cslb1" label="措施类别1">
          </el-table-column>
          <el-table-column align="center" prop="cslb2" label="措施类别2">
          </el-table-column>
          <el-table-column align="center" prop="cslb3" label="措施类别3">
          </el-table-column>
          <el-table-column align="center" prop="csff" label="措施方法">
          </el-table-column>
          <el-table-column align="center" prop="sgcs" label="施工措施">
          </el-table-column>
          <el-table-column align="center" prop="kssj" label="开始时间">
          </el-table-column>
          <el-table-column align="center" prop="jssj" label="结束时间">
          </el-table-column>
          <el-table-column align="center" prop="tjyy" label="停井原因">
          </el-table-column>
          <el-table-column align="center" prop="tjts" label="停井天数">
          </el-table-column>
          <el-table-column align="center" prop="sgdwdm" label="施工单位代码">
          </el-table-column>
          <el-table-column align="center" prop="zyptmc" label="作业平台名称">
          </el-table-column>
          <el-table-column align="center" prop="sfjy" label="是否积压">
          </el-table-column>
          <el-table-column align="center" prop="jyyy" label="积压原因">
          </el-table-column>
          <el-table-column align="center" prop="sgzt" label="施工状态">
          </el-table-column>
          <el-table-column align="center" prop="sgjd" label="施工进度">
          </el-table-column>
          <el-table-column align="center" prop="bz" label="备注">
          </el-table-column>

          <el-table-column align="center" fixed="right" width="180px" prop="approveStatus" label="审核">
            <template slot-scope="scope">
              <el-button v-if="(scope.row.approveStatus == 1 && leve == 100) || (scope.row.approveStatus == 3 && leve == 1000)" @click="handAudit(scope.row)" type="text" style="color: orange">审核</el-button>
              <el-tooltip v-else :content="scope.row.approveBz" placement="right" effect="light" :disabled="!scope.row.approveBz">
                <el-badge :is-dot="scope.row.approveBz!=''&&scope.row.approveBz!=null" class="item">
                  <el-tag :class="scope.row.approveBz?'tagstyle':''"
                  :type="
                    scope.row.approveStatus == '5'
                    ?'success'
                    :scope.row.approveStatus == '4'
                      ? 'danger'
                      : scope.row.approveStatus == '3'
                        ? ''
                        :scope.row.approveStatus == '2'
                          ? 'danger'
                          :scope.row.approveStatus == '1'
                            ? 'warning'
                            :'info'"
                    disable-transitions>{{
                    scope.row.approveStatus == '5'
                    ?'管理部通过'
                    :scope.row.approveStatus == '4'
                      ? '管理部未通过'
                      : scope.row.approveStatus == '3'
                        ? '作业区通过待管理部审核'
                        :scope.row.approveStatus == '2'
                          ? '作业区未通过'
                          :scope.row.approveStatus == '1'
                            ? '已上报待作业区审核'
                            :'待上报'
                  }}</el-tag>
                </el-badge>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
      <!-- 分页器 -->
      <el-pagination align='right'
          background
          @size-change="handleSizeChange" 
          @current-change="handleCurrentChange" 
          :current-page="pageNo"
          :page-sizes="[5,10, 20, 30, 40, 50]" 
          :page-size="pageSize" 
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
    </div>

    <!-- 弹出框 -->
    <el-dialog title="数据审核" :visible.sync="dialogFormVisible" custom-class="saveAsDialog2">
      <el-form :inline="true" :model="ysjcsqkForm" class="demo-form-inline" ref="ysjcsqkForm" label-position="left" label-width="80px">
        <el-form-item label="审核:" >
          <el-select v-model="ysjcsqkForm.approveStatus" placeholder="请选择审核状态">
            <!-- ysjcsqkForm.approveStatus=='0'? ysjcsqkForm.approveStatus == '未审核':ysjcsqkForm.approveStatus=='1'?ysjcsqkForm.approveStatus == '通过':ysjcsqkForm.approveStatus == '不通过' -->
            <!-- <el-option label="未审核" value="1"></el-option> -->
            <el-option label="通过" :value="leve==100?3:5"></el-option>
            <el-option label="不通过" :value="leve==100?2:4"></el-option>
          </el-select>
        </el-form-item>

        <el-row>
            <el-form-item label="审核备注:">
              <el-input type="textarea" v-model="ysjcsqkForm.approveBz" placeholder="请输入审核备注"></el-input>
            </el-form-item>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="shclose('ysjcsqkForm')">取 消</el-button>
        <el-button type="primary" @click="submitForm('ysjcsqkForm')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
import { getToken } from "@/utils/auth";
import yjApi from '@/api/jcsj/jcsy/yjjcsj';
import ysjcsqkApi from '@/api/jcsj/scgl/jsj/ysjcsqk';

export default {
  data() {
    return {
      leve:'',
      saveAsDialog2:'',
      // show:false,//隐藏序列
      pageNo: 1, //当前页码
      pageSize: 10, //每页显示数量
      total: 0, //总数量
      // table数据
      tableData: [],
      //当前页码
      currentPage: 1,
      //表单填报的数据
      ysjcsqkForm: {
        csid:'',
        jh:'',
        rq:'',//日期
        cslx:'',//作业类型
        cslb1: '',//作业类别1
        cslb2: '',//作业类别2
        cslb3: '',//作业类别3
        csff: '',//措施方法
        sgcs: '',//施工措施
        kssj: '',//开始时间
        jssj: '',//结束时间
        tjyy: '',//停井原因
        tjts: '',//停井天数
        sgdwdm: '',//施工单位代码
        zyptmc: '',//作业平台名称
        sfjy: '',//是否积压
        jyyy: '',//积压原因
        sgzt: '',//作业状态
        sgjd: '',//作业进度
        bz: '',//备注
        approveStatus:'',
        approveBz:'',
      },
      //验证规则
      rules: {
        csid: [
          { required: true, message: '请输入措施ID', trigger: 'blur' },
        ],
        jh: [
          { required: true, message: '请选择井', trigger: 'blur' },
        ],
        rq: [
          { required: true, message: '请选择日期', trigger: 'blur' },
        ],
      },
      //时间快捷选择
      pickerOptions: {
        // disabledDate(time) {
        //   return time.getTime() > Date.now();
        // },
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
      //获取当前日期
      currentTime:'',
      //编辑框是否显示
      dialogFormVisible: false,
      //弹出框是否是查看
      ischeck: false,
      //控制查看时不可更改数据
      isInput:false,
      //弹出框标题
      myDialogTitle: '',
      //是否新增
      isadd: true,
      //获取机构列表
      jhList:[],
    }
  },
  created(){
    this.search();
    this.$data.leve = sessionStorage.getItem("userLeve");
  },
  mounted(){
    // this.searchJh();  
    this.filterTime();
  },
  methods: {
    /**
    * 查询列表
    */
    async search() {
      // this.pageNo = pageNo; //当前页码
      // this.pageSize = pageSize; //每页显示数量
      //发送查询请求
      let res = await ysjcsqkApi.getList({pageNo:this.pageNo,pageSize:this.pageSize});
      //判断是否成功
      if(res.success){
        console.log(res.data);
        //赋值
        this.tableData = res.data.records;
        //总数量
        this.total = res.data.total;
      }
    },
    // //查询机构列表
    // async searchJh() {
    //   //发送查询请求
    //   let res = await yjApi.getList({pageNo:-1,pageSize:-1});
    //   //判断是否成功
    //   if(res.success){
    //     console.log('jg'+res.data.records);
    //     //赋值
    //     this.jhList = res.data.records;
    //     //总数量
    //   }
    // },
    //审核
    handAudit(row){
      this.$objCopy(row, this.ysjcsqkForm);
      this.ysjcsqkForm.approveStatus = ''
      this.ysjcsqkForm.approveBz = ''
      this.dialogFormVisible = true;
    },
    // 审核弹框关闭触发
    shclose(formName) {
      this.dialogFormVisible = false;
      this.$resetForm("ysjcsqkForm", this.ysjcsqkForm); //清空表单数据
      // 清空表单校验，避免再次进来会出现上次校验的记录
      this.$refs[formName].clearValidate()
    },

    //审核确认
    submitForm(formName) {
      //表单验证
      this.$refs[formName].validate(async (valid) => {
          if (valid) {
              let res = null;
              //发送审核请求
              console.log(this.ysjcsqkForm)
              res = await ysjcsqkApi.update(this.ysjcsqkForm);

              console.log(res)
              //判断是否成功
              if (res.success) {
                  // this.$message.success(res.message);
                  this.$message({ message: '修改审核状态成功！', type: 'success' });
                  //刷新
                  this.search();
                  this.$resetForm("ysjcsqkForm", this.ysjcsqkForm); //清空表单数据
                  //关闭窗口
                  this.dialogFormVisible = false;
              } else {
                console.log(res)
                  this.$message.error(res.message);
              }
          }
      })
    },
    //关闭对话框
    handleClose(done) {      
      // 清空表单
      // this.$refs['ysjcsqkForm'].resetFields();
      // 清空表单校验，避免再次进来会出现上次校验的记录
      this.$refs['ysjcsqkForm'].clearValidate()
      done()
      
    },
      // 弹框关闭触发
    close(formName) {
      this.dialogFormVisible = false;
      // 清空表单
      // this.$refs[formName].resetFields();
      // 清空表单校验，避免再次进来会出现上次校验的记录
      this.$refs[formName].clearValidate()
    },

    // submitForm(formName) {
    //   //表单验证
    //   this.$refs[formName].validate(async (valid)  => {
    //       if (valid) {
    //           let res = null;
    //           console.log('111'+this.ysjcsqkForm.bzid)
    //           //判断ID是否为空
    //           if (this.isadd) {     
    //               console.log(this.ysjcsqkForm)
    //               //发送添加请求
    //               res = await ysjcsqkApi.add(this.ysjcsqkForm);
    //           } else {
    //               //发送修改请求
    //               res = await ysjcsqkApi.update(this.ysjcsqkForm);
    //           }
    //           console.log(res)
    //           //判断是否成功
    //           if (res.success) {
    //               this.$message.success(res.message);
    //               //刷新
    //               this.search();
    //               //关闭窗口
    //               this.dialogFormVisible = false;
    //           } else {
    //             console.log(res)
    //               this.$message.error(res.message);
    //           }
    //       }
    //   })
    // },
    // handleClick(row, handle) {
    //   // console.log(row.approveStatus);
    //   this.dialogFormVisible = true;
    //   if (handle == 'check') {
    //     this.myDialogTitle = '油水井措施情况'
    //     this.ischeck = true    
    //     this.isInput = true;// 1.表单禁用
    //     // this.ysjcsqkForm = row
    //     this.$objCopy(row, this.ysjcsqkForm);//把当前要编辑的数据复制到数据域，给表单回显
    //     this.$message({ message: '成功打开', type: 'success' });
    //   } else if (handle == 'edit') {
    //         this.myDialogTitle = '油水井措施情况编辑'
    //         this.ischeck = false
    //         this.isInput = false    
    //         this.isadd = false 
    //         this.$objCopy(row, this.ysjcsqkForm);//把当前要编辑的数据复制到数据域，给表单回显
    //   } else if (handle == 'add') {
    //     // this.ysjcsqkForm ={}
    //     this.$resetForm("ysjcsqkForm", this.ysjcsqkForm); //清空表单数据
    //     this.myDialogTitle = '油水井措施情况填报'
    //     this.ischeck = false
    //     this.isadd = true
    //     this.isInput = false
    //   }
    // },

    // //删除行数据
    // async handleDelete(row) {

    //   let confirm = await this.$myconfirm("确定要删除该数据吗?");
    //   console.log(confirm)
    //   if (confirm) {
    //   //发送删除请求
    //   let res = await ysjcsqkApi.delete({ csid:row.csid,jh: row.jh,rq: row.rq });
    //   console.log(res)
    //   //判断是否成功
    //   if (res.success) {
    //       //成功提示
    //       this.$message.success(res.message);
    //       //刷新
    //       this.search();
    //   } else {
    //       //失败提示
    //       this.$message.error(res.message);
    //   }
    //   }
  
    // },
    //   //批量删除
    // handleSelectionChange(val){
    //   this.multipleSelection = val;
    //   console.log(this.multipleSelection);
    // },
    // async handleBDelete() {
    //   //判断是否可以删除
    //   //确认是否删除
    //   let confirm = await this.$myconfirm("确定要删除该数据吗?");
    //   console.log(confirm)
    //   var ids = []
    //   if (confirm) {
    //       for(let j=0 ; j<this.multipleSelection.length; j++){
    //           if (this.multipleSelection[j].approveStatus == 2) {
    //               //提示不能删除
    //               console.log(this.multipleSelection[j].approveStatus)
    //               this.$message({ message: '有已通过数据不可删除！', type: 'error' });
    //               return;
              
    //           }
    //           ids[j] = this.multipleSelection[j].id
    //       }
    //       console.log("ids",ids)
    //       // const ids = ids.toString();
    //       // console.log("ids",ids)
    //       //发送删除请求
    //       console.log('111')
    //       let res = await xcwxApi.Bdelete(ids);
    //       console.log('222')
    //       console.log(res)
    //       //判断是否成功
    //       if (res.success) {
    //       //成功提示
    //       this.$message.success(res.message);
    //       //刷新
    //       this.search();
    //       } else {
    //       //失败提示
    //       this.$message.error(res.message);
    //       }
    //   }
    // },

    /*** 当每页数量发生变化时触发该事件 */
    handleSizeChange(size) {
      console.log(size);
      this.pageSize = size;
      //将每页显示的数量交给成员变量
      this.search(this.pageNo, size);
    },
    /*** 当页码发生变化时触发该事件 */
    handleCurrentChange(page) {
      console.log(page);
      this.pageNo = page;
      //调用查询方法
      this.search(page, this.pageSize);
    },
    // 序号计算
    indexMethod (index) {
    // index默认在0开始，这里+1
      return index + 1 + (this.pageNo - 1) * this.pageSize
    },
    // 获取当前日期
    filterTime() {
      var date = new Date();
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? '0' + m : m;
      var d = date.getDate();
      d = d < 10 ? '0' + d : d;
      this.currentTime = y + '-' + m + '-' + d;
      // console.log(typeof(new Date(this.currentTime)));
    },
  }
}
</script>

<style lang="scss" scoped>
// 标题
.mytitle {
  font-size: large;
  padding-left: 10px;
  margin-bottom: 16px;
  float: left;
}

//按钮组
.myButtons {
  float: right
}

//格子的样式
.bg-white {
  background: #ffffff;
}

.grid-content {
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 4px;
}

.calendar ::v-deep .el-button-group::before {
  display: none;
}

.calendar ::v-deep .el-button-group::after {
  display: none;
}

// 分割线样式
.el-divider--horizontal {
  display: block;
  height: 2px;
  width: 100%;
  margin: 24px 0;
}

// 表单各项的样式
.el-form-item {
  margin: 15px 10px 15px 10px;
}

//表单禁用字体样式
.el-input.is-disabled ::v-deep .el-input__inner {
    color: #606266;
  }
//对话框宽度
// .customWidth{
//         width:80%;
//     }
::v-deep .saveAsDialog {
  width: 50% !important;
}

::v-deep .el-table .cell{overflow: unset}
//日期选择框宽度
.el-date-editor.el-input, .el-date-editor.el-input__inner { width: 200px; }

.el-input {
  width: 200px;
}

::v-deep .saveAsDialog2 {
    width: 25% !important;
  }

  .el-textarea{
    width: 105%;
  }

  .tagstyle{
    cursor: pointer;
  }

  ::v-deep .el-table .cell{
    overflow: visible;
  }
</style>